package com.hualan.sfzy.controller;

import com.hualan.sfzy.model.entity.ConsultNotice;

import com.hualan.sfzy.service.ConsultNoticeService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.hualan.sfzy.constant.CommonConstant.*;

/**
 * 咨询公告管理控制器
 */
@RestController
@RequestMapping("/consultNotice")
public class ConsultNoticeController {

    @Autowired
    private ConsultNoticeService consultNoticeService;

    /**
     * 添加咨询公告
     */
    @PostMapping("/add")
    public Result add(@RequestBody ConsultNotice consultNotice) {
        int result = consultNoticeService.add(consultNotice);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 编辑咨询公告
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody ConsultNotice consultNotice) {
        int result = consultNoticeService.edit(consultNotice);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 删除咨询公告
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        int result = consultNoticeService.remove(id);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 批量删除咨询公告
     */
    @DeleteMapping("/removeBatch")
    public Result removeBatch(@RequestBody Integer[] ids) {
        int result = consultNoticeService.removeBatch(ids);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 查询所有咨询公告
     */
    @GetMapping("/find")
    public Result find() {
        List<ConsultNotice> consultNotices = consultNoticeService.find();
        return Result.success(consultNotices);
    }

    /**
     * 分页查询咨询公告
     */
    @GetMapping("/findPage")
    public Result findPage(@RequestParam(value = PAGE_NUM, defaultValue = PAGE_NUM_DEFAULT) Integer pageNum,
                          @RequestParam(value = PAGE_SIZE, defaultValue = PAGE_SIZE_DEFAULT) Integer pageSize,
                          ConsultNotice consultNotice) {
        Map<String, Object> result = consultNoticeService.findPage(pageNum, pageSize, consultNotice);
        return Result.success(result);
    }

    /**
     * 根据ID查询咨询公告
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id) {
        ConsultNotice consultNotice = consultNoticeService.findById(id);
        return Result.success(consultNotice);
    }

    /**
     * 分页条件查询咨询公告
     */
    @GetMapping("/findNoticePage")
    public Result findNoticePage(@RequestParam(value = PAGE_NUM, defaultValue = PAGE_NUM_DEFAULT) Integer pageNum,
                                @RequestParam(value = PAGE_SIZE, defaultValue = PAGE_SIZE_DEFAULT) Integer pageSize,
                                ConsultNotice query) {
        Map<String, Object> result = consultNoticeService.findPage(pageNum, pageSize, query);
        return Result.success(result);
    }
} 